<?php

// phpMyRealty 3
//
// File Name: banner.php
// File Location : ./
//
// Copyright (c)2009 phpMyRealty.com
//
// e-mail: support@phpMyRealty.com

// Select a random listing from the database
if (!defined('PMR') || (defined('PMR') && PMR != 'true')) die();

if ($conf['banner_featured'] == 'ON')
 $featured_only = ' AND featured = "A" ';
else
 $featured_only = '';

$r_banner = $db->query ('SELECT id, featured, type, title, banner FROM ' . PROPERTIES_TABLE . ' WHERE approved = 1 AND banner <> "" ' . $featured_only . ' ORDER BY RAND() LIMIT 1');

if ($db->numrows($r_banner) > 0)
 {

  $f_banner = $db->fetcharray($r_banner);

  if ($conf['rewrite'] == 'ON')
   $banner_random = '<a href="' . URL . '/Listing/Banner/' . $f_banner['id'] . '.html"><img src="' . URL . '/banners/' . $f_banner['banner'] . '" border="0" class="image" alt=""><br /></a>';
  else
   $banner_random = '<a href="' . URL . '/viewlisting.php?id=' . $f_banner['id'] . '"><img src="' . URL . '/banners/' . $f_banner['banner'] . '" border="0" class="image" alt=""><br /></a>';

  if ($conf['rewrite'] == 'ON')
   $bannerlink = URL . '/Listing/' . rewrite ( getnamebyid ( TYPES_TABLE, $f_banner['type'] ) ) . '/' . $f_banner['id'] . '.html';
  else
   $bannerlink = URL . '/viewlisting.php?id=' . $f_banner['id'];

  echo '<p align="center">' . $banner_random . '<br /><a href="' . $bannerlink . '">' . $f_banner['title'] . '</a></p>';

 }

?>